﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Abp.Domain.Repositories;
using Abp.Domain.Services;
using Abp.UI;
using FwProject.Core.AppVersion;

namespace FwProject.Manager
{
    public class AppVersionInfoManager: IDomainService
    {
        private readonly IRepository<AppVersionManger, Guid> _appVersionRepository;

        public AppVersionInfoManager(IRepository<AppVersionManger, Guid> appVersionRepository)
        {
            _appVersionRepository = appVersionRepository;
        }

        public async Task<Guid> CreateAppVersion(AppVersionManger appVersion)
        {

            var model = _appVersionRepository.GetAll().Where(o =>o.AppVersion ==appVersion.AppVersion).FirstOrDefault();
            if (model != null)
                throw new UserFriendlyException("当前版本已存在");

            return await _appVersionRepository.InsertAndGetIdAsync(appVersion);
        }

        public async Task UpdateAppVersion(AppVersionManger appVersion)
        {

            await _appVersionRepository.UpdateAsync(appVersion);
        }


        public async Task DeleteAppVersion(AppVersionManger appVersion)
        {

            await _appVersionRepository.DeleteAsync(appVersion);
        }
    }
}
